package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * 将指定专辑保存到索引库中
     *
     * @param albumId
     * @return
     */
    @Operation(summary = "将指定专辑保存到索引库中")
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * 将指定专辑从索引库中下架
     *
     * @param albumId
     * @return
     */
    @Operation(summary = "将指定专辑从索引库中下架")
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    /**
     * 站内专辑搜索
     *
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "站内专辑搜索")
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    /**
     * 获取一级分类置顶七个三级分类下包含热度最高的六个专辑列表
     *
     * @param category1Id
     * @return
     */
    @Operation(summary = "获取一级分类置顶七个三级分类下包含热度最高的六个专辑列表")
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> getTop6(@PathVariable Long category1Id) {
        List<Map<String, Object>> list = searchService.getTop6(category1Id);
        return Result.ok(list);

    }

    /**
     * 搜索关键字自动补全
     *
     * @param keyword
     * @return
     */
    @Operation(summary = "搜索关键字自动补全")
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }

    /**
     * 统计ES中不同分类下不同维度的热度较高的专辑列表，将其存入Redis缓存中
     *
     * @return
     */
    @Operation(summary = "统计ES中不同分类下不同维度的热度较高的专辑列表，将其存入Redis缓存中")
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking() {
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

    /**
     * 根据一级分类id以及排序字段获取TOP10专辑列表
     *
     * @param category1Id
     * @param dimension
     * @return
     */
    @Operation(summary = "根据一级分类id以及排序字段获取TOP10专辑列表")
    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable Long category1Id,
                                                        @PathVariable String dimension) {
        List<AlbumInfoIndex> list = searchService.findRankingList(category1Id, dimension);
        return Result.ok(list);
    }

}

